<template>
  <div class="dataView">
    <div class="header">
      <!-- <div class="toLogin" @click="toLogin" title="退出登录">
                <el-icon color="#666" style="font-size: 24px;">
                    <User />
                </el-icon>
            </div> -->
      <div class="toHome" @click="toMain">
        <el-icon color="#666" style="font-size: 24px">
          <HomeFilled />
        </el-icon>
      </div>
    </div>
    <div class="dataContain" :style="{ height: hHeight - 70 + 'px' }">
      <div class="leftNave">
        <ul>
          <li
            :class="currentNavCode == item.code ? 'act' : ''"
            v-for="item in navList"
            :key="item.code"
            @click="toPath(item)"
          >
            <el-icon class="elIcon" :size="20">
              <UploadFilled v-if="item.code == 'upload'" />
              <Platform v-if="item.code == 'bigscreenData'" />
              <Guide v-if="item.code == 'waterYield'" />
              <MagicStick v-if="item.code == 'assay'" />
              <EditPen v-if="item.code == 'examine'" />
              <Tools v-if="item.code == 'equipment'" />
            </el-icon>
            <span class="">{{ item.name }}</span
            ><i
              class="count"
              v-if="item.code == 'examine' && queryUnAuditCount > 0"
              >{{ queryUnAuditCount > 99 ? "99+" : queryUnAuditCount }}</i
            >
          </li>
        </ul>
      </div>
      <el-scrollbar class="containRouter">
        <router-view></router-view>
      </el-scrollbar>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref, nextTick } from "vue";
import { useRouter } from "vue-router";
import {
  HomeFilled,
  UploadFilled,
  Platform,
  Guide,
  MagicStick,
  User,
  EditPen,
  Tools,
} from "@element-plus/icons-vue";
import dataList from "../../https/dataList";
import Storage from "@/utils/storage.js"; // storage工具类，简单的封装
const hHeight = ref(0);
const currentNavCode = ref("/bigscreenData");
const localTypeUnit = ref(Storage.localGet("depId"));
const navList = ref([
  // { name: '数据上传', code: 'upload', toPath: '/upload', icon: '' },
  {
    name: "大屏数据",
    code: "bigscreenData",
    toPath: "/bigscreenData",
    icon: "",
  },
  { name: "生产数据", code: "waterYield", toPath: "/waterYield", icon: "" },
  { name: "化验数据", code: "assay", toPath: "/assay", icon: "" },
]);
if (localTypeUnit.value == 1) {
  navList.value = [
    {
      name: "大屏数据",
      code: "bigscreenData",
      toPath: "/bigscreenData",
      icon: "",
    },
    { name: "生产数据", code: "waterYield", toPath: "/waterYield", icon: "" },
    { name: "化验数据", code: "assay", toPath: "/assay", icon: "" },
    { name: "数据审核", code: "examine", toPath: "/examine", icon: "" },
    { name: "设备管理", code: "equipment", toPath: "/equipment", icon: "" },
  ];
}
if (localTypeUnit.value == 2) {
  navList.value = [
    { name: "生产数据", code: "waterYield", toPath: "/waterYield", icon: "" },
    { name: "化验数据", code: "assay", toPath: "/assay", icon: "" },
    { name: "设备管理", code: "equipment", toPath: "/equipment", icon: "" },
  ];
}
if (localTypeUnit.value == 3) {
  navList.value = [
    { name: "生产数据", code: "waterYield", toPath: "/waterYield", icon: "" },
    { name: "化验数据", code: "assay", toPath: "/assay", icon: "" },
    { name: "设备管理", code: "equipment", toPath: "/equipment", icon: "" },
  ];
}
if (localTypeUnit.value == 4) {
  navList.value = [
    { name: "生产数据", code: "waterYield", toPath: "/waterYield", icon: "" },
    { name: "化验数据", code: "assay", toPath: "/assay", icon: "" },
    { name: "设备管理", code: "equipment", toPath: "/equipment", icon: "" },
  ];
}
if (localTypeUnit.value == 5) {
  navList.value = [
    { name: "生产数据", code: "waterYield", toPath: "/waterYield", icon: "" },
    { name: "化验数据", code: "assay", toPath: "/assay", icon: "" },
    { name: "设备管理", code: "equipment", toPath: "/equipment", icon: "" },
  ];
}
if (localTypeUnit.value == 6) {
  navList.value = [
    { name: "设备管理", code: "equipment", toPath: "/equipment", icon: "" },
  ];
}
const queryUnAuditCount = ref(0);
onMounted(() => {
  nextTick(() => {
    hHeight.value = document.documentElement.clientHeight;
  });

  // console.log(router, router.currentRoute.value.path);
  router.push({ path: router.currentRoute.value.path });
  currentNavCode.value = router.currentRoute.value.path.replace("/", "");
  queryUnAudit();
});
const router = useRouter();
// console.log(router, router.currentRoute.value, router.currentRoute.value.path);
currentNavCode.value = router.currentRoute.value.path.replace("/", "");

const toMain = () => {
  router.push({ path: "/main" });
};
// const toLogin = () => {
//     router.push({ path: '/login' })
// }
const toPath = (item) => {
  currentNavCode.value = item.code;
  router.push({ path: item.toPath });
};
const queryUnAudit = () => {
  dataList.queryUnAudit().then((res) => {
    queryUnAuditCount.value = res.data.data;
  });
};
</script>
<style scoped lang="less">
.dataView {
  width: 100%;
  height: 100%;
  background: #f5f6fa;
}

.header {
  height: 50px;
  width: 100%;
  background: #fff;
  border-bottom: 1px solid #ccc;
  margin-bottom: 20px;
  box-sizing: border-box;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: row;

  .toHome {
    box-sizing: border-box;
    width: 50px;
    height: 50px;
    // background: #63b2ee;
    text-align: center;
    z-index: 100;
    cursor: pointer;
    padding-top: 12px;
  }

  .toLogin {
    box-sizing: border-box;
    width: 50px;
    height: 50px;
    // background: #63b2ee;
    text-align: center;
    z-index: 100;
    cursor: pointer;
    padding-top: 12px;
  }
}

.dataContain {
  width: 100%;
  display: flex;
  flex-direction: row;
  background: #fff;

  .leftNave {
    width: 220px;
    background: #eaedf1;

    ul {
      width: 100%;

      li {
        width: 100%;
        height: 48px;
        line-height: 48px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-items: flex-start;
        color: #333;
        font-size: 14px;
        cursor: pointer;

        .elIcon {
          width: 40px;
          padding-left: 10px;
        }

        &.act {
          background: #fff;
        }
      }
    }
  }

  .containRouter {
    width: 100%;
    padding: 30px;
    box-sizing: border-box;
  }
}
.count {
  width: 20px;
  height: 20px;
  background: red;
  border-radius: 10px;
  text-align: center;
  line-height: 20px;
  color: #fff;
  font-size: 10px;
  margin-left: 10px;
}
</style>
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
</style>
